
	
	
	use  MxFLS_final , clear		
	
		  	   
/* select sub sample   */ 
		
		keep if hhpotentialmigration ==1 
		drop if attrited_hh==1		
		
		keep if ruralarea==1
		
  
	cap drop hh
	by folio: g hh= _n==1
		
  
			
			g son = rel_head ==3 & male==1
			g daughter = rel_head ==3 & male==0
		
			
			foreach i in 1 2 3 4 5 {
			g hhsize`i'= hhsize==`i'
			}
			replace hhsize5 = hhsize >=5
			
		   	bys folio: egen HH_averagetrans02 = mean( IND_moneyreceive02)
			g HH_ownprivatrans= HH_averagetrans02>0 if HH_averagetrans02!=.
			bys folio: egen HH_transf_percap02 = total( IND_moneyreceive02)
			replace HH_transf_percap02= HH_transf_percap02/HH_attasio_scale02 
			
			replace HH_constot02= . if  HH_foodcons02==. | HH_nonfood02==.
			cap drop consattana02 food_consattana02 nonfood_consattana02

			cap drop 	consattana02 
			g consattana02 = HH_constot02/HH_attasio_scale02  
			g food_consattana02 = HH_foodcons02/HH_attasio_scale02  
			g nonfood_consattana02 = HH_nonfood02/HH_attasio_scale02  
		
			g  hh_labinc_percap02 = HH_labinc_month02/ HH_attasio_scale02  
			
			g  hh_socialtrans_percap02 = HH_socialtrans02/12  /* monthly*/
			replace hh_socialtrans_percap02= hh_socialtrans_percap02 /HH_attasio_scale02 

			
	     foreach v in consattana02 food_consattana02 nonfood_consattana02  HH_averagetrans02 IND_moneyreceive02 ///
					hh_socialtrans_percap02 HH_transf_percap02    hh_labinc_percap02 { 
		  _pctile `v' if `v' >0, p ( 99)
			replace `v' = . if `v' >= r(r1) 		
		}
		*
		   			 
			label var hh_socialtrans_percap02  "hh social transfer per cap" 
			label var HH_transf_percap02 "hh transfers per cap"
			label var  hh_labinc_percap02 "hh labincome per cap"
			label var workLW02   "Work last week"  
			label var agriactivity02  "Family farm work" 
			label var hhsize1 "hhsize=1"
			label var hhsize2 "hhsize=2" 
			label var hhsize3 "hhsize=3"
			label var hhsize4 "hhsize=4" 
			label var hhsize5 "hhsize $\geq$ 5"
			label var    nbage13minus "nb children <14 yold"
			label var nbage55plus "nb elderly > 55 yold"
			label var  wealthindex  "Wealth index (PCA)"
		    label var  ln_socialnonlabincome "public transfers (log)"
			label var hhrelativeUS "family network in the U.S."
			label var hhreturnees "U.S. returnees at home"
			 
			label var hhusmigrant "hh out-migration to US (2002-2005)"
			label var hhmexmigrant  "hh out-migration within Mexico (2002-2005)"
			
			label var consattana02 "Consumption per adu equiv."
			label var food_consattana02  "Food Consumption per adu equiv."
			label var nonfood_consattana02 "NonFood Consumption per adu equiv."
					
			label var HH_ownprivatrans "HH receive private transfers"
			label var HH_averagetrans02 "Av. amount of private transfers in the hh"
			
			label var  food_attana_0502 "Food Consumption per adu equiv. 2005-2002"
			label var nonfood_attana_0502  "NonFood Consumption per adu equiv. 2005-2002"
			label var cons_attana_0502 "Consumption per adu equiv. 2005-2002"
		
	
	
		

			global statdesc_2    age male    yedu  head spouse son daughter ///
								workLW02   workLW_noagrw02    workLW_agrw02   workLW_self02 agriactivity02 
			/*single */ 
			
	
		
		global HH_desc hhsize hhsize1 hhsize2 hhsize3 hhsize4 hhsize5   nbage13minus nbage55plus /// 
			   hh_higestgrade3  hh_higestgrade4 wealthindex   ///
		       hhrelativeUS hhreturnees ///		
			   nbmaleage3654 nbmaleage1435  food_consattana02 nonfood_consattana02 consattana02 hh_socialtrans_percap02  hh_labinc_percap02 HH_transf_percap02   HH_ownprivatrans 
			
			
			eststo clear
			forvalues i = 0/1 {
			 qui eststo  HH`i' : estpost tabstat  ${HH_desc}   if  hh==1 & hhusmigrant==`i'  , statistics(n mean  sd   ) columns(statistics) 	
			}
			
			qui eststo HHtest : estpost ttest ${HH_desc}  if  hh==1 , by(hhusmigrant) 
		
		
			forvalues i = 0/1 {
			qui eststo  A`i' : estpost tabstat     ${statdesc_2}   ///
							   if   hhusmigrant==`i' & age >=15 , statistics(n mean  sd   ) columns(statistics) 	
			}
			forvalues i = 0/1 {
			qui eststo  B`i' : estpost tabstat   ${statdesc_2}   ///
							   if   usmigrant==`i' & hhusmigrant==1 & age >=15 , statistics(n mean  sd   ) columns(statistics) 	
			}
			*
				
		 qui  eststo test_A  : estpost ttest  ${statdesc_2} if age >=15  , by(hhusmigrant)
		 qui eststo  test_B  : estpost ttest  ${statdesc_2} if age >=15 & usmigrant==0  , by(hhusmigrant)
		
*************************************************************************************************************************
*		TABLE A1  – PANEL A  – Household and individual initial characteristics in 2002 across migration status
*************************************************************************************************************************
 		
		
		nois esttab  HH0 HH1 HHtest  , star(* 0.10 ** 0.05 )  label replace smcl ///
			cells( `"mean( fmt(2) pattern(1 1 0 ) ) sd( par fmt(2) pattern(1 1 0))  b(star pattern(0 0 1  ))"' ) mtitle( "no hhmig" "hhmig" "ttest")
			
*************************************************************************************************************************
*		TABLE A1  – PANEL B  – Household and individual initial characteristics in 2002 across migration status
*************************************************************************************************************************
 		
	
		nois esttab  A0 A1 B0  test_A test_B , star(* 0.10 ** 0.05 )  label replace ///
		cells( `"mean( fmt(2) pattern(1 1 1 0 0  ) ) sd( par fmt(2) pattern(1 1 1 0 0 ))  b(star pattern(0 0 0 1 ))"' ) ///
		mtitle( "no hhmig (1) " "hhmig (2) " "left-behind (3)" "test (1-2) " "test (1-3)") 
	 		

*************************************************************************************************************************
*		TABLE A.2 – Variation in household consumption and labor supply by migration status
*************************************************************************************************************************
 	
	
		*** In difference 2005- 2002 
		
		global labor workLW0502   workLW_noagrw0502    workLW_agrw0502   workLW_self0502  agriactivity0502
		 
		global consdiff  food_attana_0502 nonfood_attana_0502  cons_attana_0502
		


		forvalues i = 0/1 {
		qui eststo  DIFF`i' : estpost tabstat   ${labor}     if   usmigrant==0 & hhusmigrant==`i'  & age >=15 , statistics(n mean  sd   ) columns(statistics) 	
		}
		*		
		qui  eststo test_diff  : estpost ttest  ${labor}  if usmigrant==0 & age >=15  , by(hhusmigrant)


		forvalues i = 0/1 {
		qui eststo  HHdiff`i' : estpost tabstat  ${consdiff}   if  hh==1 & hhusmigrant==`i'  , statistics(n mean  sd   ) columns(statistics) 	
		}

		qui eststo HHtestdiff : estpost ttest ${consdiff}  if  hh==1 , by(hhusmigrant) 

		nois esttab   DIFF0 DIFF1   test_diff,  star(* 0.10 ** 0.05 )  label replace nonumbers nogaps noeqlines compress	nodepvars nonumbers   nonotes    /// ///
		cells( `"mean( fmt(2) pattern(1 1 0 ) )  b(star pattern(0 0 1  )) "' `"sd( par fmt(2) pattern(1 1 0))  se(par pattern(0 0 1  )) "' ) mtitle( "no hhmig" "hhmig" "ttest")

		nois esttab    HHdiff0  HHdiff1   HHtestdiff  , append star(* 0.10 ** 0.05 )  label  nonumbers nogaps noeqlines compress	nodepvars nonumbers   nonotes  ///
		cells( `"mean( fmt(2) pattern(1 1 0 ) )  b(star pattern(0 0 1  )) "' `"sd( par fmt(2) pattern(1 1 0))  se(par pattern(0 0 1  )) "' ) mtitle( "no hhmig" "hhmig" "ttest")


		

		
